import axios from 'axios'
const {MODE, VITE_BASE_UPLOAD_URL} = import.meta.env

// 上传专用axios

const config = {
  baseURL: MODE === 'development' ? '/upload' : VITE_BASE_UPLOAD_URL,
  timeout: 30000,
  headers: {
    'Content-Type': 'multipart/form-data'
  }
}

const http = axios.create(config)

// 添加请求拦截器
http.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么

  // 暂时是写死的token
  config.headers.Authorization = 'Bearer 2f68dbbf-519d-4f01-9636-e2421b68f379'
  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

// 添加响应拦截器
http.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response.data
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error)
})


// 上传卡牌图片
export function uploadCardImageApi ({ image, uid }) {
  return http.post(`/card/${uid}/image/upload/`, {image})
}

// 卡牌图片重新上传
export function updateCardImageApi ({ image, uid, id }) {
  return http.post(`/card/${uid}/image/${id}/upload/`, {image})
}

// 上传卡牌图片
export function uploadOrderImageApi ({ image, uid }) {
  return http.post(`/sendorderset/${uid}/image/upload/`, {image})
}

// 卡牌图片重新上传
export function updateOrderImageApi ({ image, uid, id }) {
  return http.post(`/sendorderset/${uid}/image/${id}/upload/`, {image})
}

// 视频上传
export function uploadVideoApi (video) {
  return http.post('/video/upload/', {video, auth_token: 'modf9-j32tj-21rfqs1245v,bezenkmq=emfv'})
}
